package d2_properties;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;

/**
 * 目标：读取属性文件，判断是否存在张三，存在年龄改成18
 */
public class PropertiesTest3 {
    public static void main(String[] args) throws Exception {
        //加载属性文件的键值对到程序中来
        Properties properties = new Properties();

        //2.开始加载
        properties.load(new FileReader("D:\\idea\\idea code\\java-practice\\practice\\properties-xml-log-app\\users2.properties"));
        //3.判断是否包含张三这个键
        if (properties.containsKey("张三")){
            properties.setProperty("张三","18");
        }
        //4.把properties的键值对数据重新写出去到属性文件中去
        properties.store(new FileWriter("D:\\idea\\idea code\\java-practice\\practice\\properties-xml-log-app\\users2.properties"),
                " success!");

    }
}
